#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+7;
int n,a[N];
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        for(int i = 0;i < n;i++) scanf("%d",&a[i]);
        int res = 0;
        for(int i = 0;i < (1<<n);i++){
            int cnt = 0;
            for(int j = 0;j < n;j++){
                for(int k = j-1;k >= 0;k--){
                    if(((i>>j)&1) == ((i>>k)&1)){
                        if(a[j] == a[k]) cnt += a[k];
                        break;
                    }
                }
            }
            res = max(res,cnt);
        }
        printf("%d\n",res);
    }
    return 0;
}
